<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        .box {
            width: 400px;
            height: 400px;
            background-color: antiquewhite;
            margin: 100px auto;
        }

        .box .mingzi {
            text-align: center;
            font-weight: bold;
            font-size: 20px;
        }

        .box div {
            margin-top: 20px;
        }

        .box .zz {
            margin-left: 20px;
        }

        input {
            width: 300px;
            height: 30px;
            /* outline: none; */
        }

        .an {
            margin: 0 70px;
        }
    </style>
</head>


<body>
    <div class="box">
        <div class="mingzi">登录页面</div>
        <div class="zz">账号：<input type="text"></div>
        <div class="zz"> 密码：<input type="password" name="" id=""></div>
        <div class="an"><input type="button" value="登录"></div>
    </div>
</body>

</html>
<script src="./ajax.js"></script>
<script>
    var input = document.querySelectorAll('.box input')

    input[2].onclick = function () {
        console.log(input[1].value);
        if (input[0].value && input[1].value) {
            if (/^\d{4}$/.test(input[1].value)) {
                ajax('get', './data.json', {  }, function (data) {
                 var index=   data.findIndex((item) => {
                     return   item.username == input[0].value && item.password == input[1].value
                    })
                    if(index==-1){
                        alert('登录账户或者密码不存在')
                    }else{
                        alert('登录成功')
                    }
                })

            }
        }
    }
</script>